package com.example.composemodifiterdemo

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview

/**
 * @auth: njb
 * @date: 2022/12/31 20:57
 * @desc:
 */
class CustomGraphicalActivity :ComponentActivity(){
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            canvas()
        }
    }

    @Preview
    @Composable
    private fun canvas() {
        Column() {
            Canvas(modifier = Modifier.fillMaxSize()) {
                val canvasWidth = 150f
                val canvasHeight = 150f

                drawLine(
                    start = Offset(x = canvasWidth, y = 0f),
                    end = Offset(x = 0f, y = canvasHeight),
                    color = Color.Blue
                )
            }

            Canvas(modifier = Modifier.fillMaxSize()) {
                val canvasWidth = 150f
                val canvasHeight = 150f

                drawLine(
                    start = Offset(x = canvasWidth, y = 0f),
                    end = Offset(x = 0f, y = canvasHeight),
                    color = Color.Blue,
                    strokeWidth = 5F
                )
            }

            Canvas(modifier = Modifier.fillMaxSize()) {
                val canvasWidth = 150f
                val canvasHeight = 150f
                drawCircle(
                    color = Color.Blue,
                    center = Offset(x = canvasWidth / 2, y = canvasHeight / 2),
                    radius = size.minDimension / 4
                )
            }
            Canvas(modifier = Modifier.fillMaxSize()) {
                val canvasQuadrantSize = size / 2F
                drawRect(
                    color = Color.Green,
                    size = canvasQuadrantSize
                )
            }
          /*  val canvasQuadrantSize = size / 2F
            inset(50F, 30F) {
                drawRect(
                    color = Color.Green,
                    size = canvasQuadrantSize
                )
            }
            val canvasSize = size
            val canvasWidth = size.width
            val canvasHeight = size.height
            drawRect(
                color = Color.Gray,
                topLeft = Offset(x = canvasWidth / 3F, y = canvasHeight / 3F),
                size = canvasSize / 3F
            )

            rotate(degrees = 45F) {
                drawRect(
                    color = Color.Gray,
                    topLeft = Offset(x = canvasWidth / 3F, y = canvasHeight / 3F),
                    size = canvasSize / 3F
                )
            }

            withTransform({
                translate(left = canvasWidth / 5F)
                rotate(degrees = 45F)
            }) {
                drawRect(
                    color = Color.Gray,
                    topLeft = Offset(x = canvasWidth / 3F, y = canvasHeight / 3F),
                    size = canvasSize / 3F
                )
            }*/
        }
    }
}